import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:niuniu_lulu/index/index.dart';
import 'package:niuniu_lulu/index/model/app_theme.dart';
import 'package:niuniu_lulu/index/page/index_page.dart';
import 'package:provider/provider.dart';

import '../index/index.dart';
import '../index/index.dart';

class MainHome extends StatefulWidget {
  @override
  _MainHomeState createState() => _MainHomeState();
}

class _MainHomeState extends State<MainHome>  with SingleTickerProviderStateMixin{
  TabController _tabController;
  List tabs = ["牛一", "牛二"];

  @override
  void initState() {
    super.initState();
    // 创建Controller
    _tabController = TabController(length: tabs.length, vsync: this);
  }
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: true);
    return Scaffold(
        appBar: AppBar(
          title: Text("一切都好"),
          bottom: TabBar(   //生成Tab菜单
            controller: _tabController,
            tabs: tabs.map((e) => Tab(text: e)).toList()
          ),
          leading: Builder(builder: (context){
            return IconButton(
              icon: Icon(Icons.menu, color: Colors.white), //自定义图标
              onPressed: () {
                // 打开抽屉菜单
                Scaffold.of(context).openDrawer();
              },
            );
          }),
        ),
      drawer: new MyDrawer(),
      body: TabBarView(
        controller: _tabController,
        children: tabs.map((e) {
          if (e == "牛一") {
            return ChangeNotifierProvider(
                create: (_) => InputControllers4(),
                child: IndexPage()
            );
          }else{
            return ChangeNotifierProvider(
                create: (_) => InputControllers4(),
                child: GroupTwoPage()
            );
          }
        }).toList(),
      )
    );
  }
}

class MyDrawer extends StatelessWidget {
  const MyDrawer({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: MediaQuery.removePadding(
        context: context,
        removeTop: false,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Expanded(
              child: Consumer<AppTheme>(builder: (widget,model,child){
                return ListView(
                  children: <Widget>[
                    MaterialButton(onPressed: (){
                      model.GroupOneAInputShow = !model.GroupOneAInputShow;
                    },child:
                    model.GroupOneAInputShow?Row(children: [Icon(Icons.keyboard_hide), Text("隐藏牛一上")]):Row(children: [Icon(Icons.keyboard), Text("显示牛一上")])
                    ),
                    MaterialButton(onPressed: (){
                      model.GroupOneBInputShow = !model.GroupOneBInputShow;
                    },child:
                    model.GroupOneBInputShow?Row(children: [Icon(Icons.keyboard_hide), Text("隐藏牛一下")]):Row(children: [Icon(Icons.keyboard), Text("显示牛一下")])
                    ),
                    MaterialButton(onPressed: (){
                      model.GroupTwoInputShow = !model.GroupTwoInputShow;
                    },child:
                    model.GroupTwoInputShow?Row(children: [Icon(Icons.keyboard_hide), Text("隐藏牛二")]):Row(children: [Icon(Icons.keyboard), Text("显示牛二")])
                    )
                  ],
                );
              }),
            ),
          ],
        ),
      ),
    );
  }
}
